using System;
using Castle.ActiveRecord;
using Iesi.Collections.Generic;
using Castle.Components.Validator;

namespace WineCellar.Data
{
    [ActiveRecord("Wines", Schema = "dbo",UseAutoImport = false)]
    public partial class Wine
	{
		#region privates
		private string name;

        private string producer;

        private string appelation;

        private string colorType;        

        private Nullable<DateTime> dateAdded;        

        private Nullable<int> id;

        private Region region;

        private User addedBy;

        private ISet<Raisin> raisins = new HashedSet<Raisin>();
		#endregion

		#region props

		[Property("Name", ColumnType = "String", NotNull = true)]
		[ValidateNonEmpty("Name is a required field")]
		public virtual string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }

        [Property("Producer", ColumnType = "String")]
		public virtual string Producer
        {
            get
            {
                return this.producer;
            }
            set
            {
                this.producer = value;
            }
        }

        [Property("Appelation", ColumnType = "String")]
		public virtual string Appelation
        {
            get
            {
                return this.appelation;
            }
            set
            {
                this.appelation = value;
            }
        }

        [Property("ColorType", ColumnType = "String")]
		public virtual string ColorType
        {
            get
            {
                return this.colorType;
            }
            set
            {
                this.colorType = value;
            }
        }

        [Property("DateAdded", ColumnType = "Timestamp")]
		public virtual Nullable<DateTime> DateAdded
        {
            get
            {
                return this.dateAdded;
            }
            set
            {
                this.dateAdded = value;
            }
        }

        [PrimaryKey(PrimaryKeyType.Identity)]
        public virtual Nullable<int> Id
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }

        [BelongsTo("RegionId",NotNull = true)]
        public virtual Region Region
        {
            get
            {
                return this.region;
            }
            set
            {
                this.region = value;
            }
        }

        [BelongsTo("UserAdded",NotNull = true)]
        public virtual User AddedBy
        {
            get
            {
                return this.addedBy;
            }
            set
            {
                this.addedBy = value;
            }
        }

		[HasAndBelongsToMany(typeof(Raisin), ColumnRef = "RaisinId", ColumnKey = "WineId", Table = "Raisins2Wines", Lazy = true)]          
        public virtual ISet<Raisin> Raisins
        {
            get{return raisins;}
            set{raisins = value;}
		}
		#endregion


		public override string ToString()
        {
            return this.Name;
        }
    }
}
